/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package creature;

import java.util.ArrayList;
import place.TargetPlace;
import processing.core.PVector;

/**
 *
 * @author user
 */
class AntLibrary {

    public static PVector getClosestAnt(PVector loc, float sightrange, ArrayList<AntCreature> ants) {
        PVector target = null;
        float currentDistance = 0;
        for (AntCreature a : ants) {

            float distance = PVector.sub(loc, a.getLoc()).mag();
            if (distance <= sightrange) {
                if (target == null) {
                    target = a.getLoc();
                    currentDistance = distance;
                } else if (distance < currentDistance) {
                    target = a.getLoc();
                    currentDistance = distance;
                }
            }

        }
        return target;
    }

    

    static PVector getClosestTarget(PVector loc, float sightrange, ArrayList<TargetPlace> targets) {
        PVector target = null;
        float currentDistance = 0;
        for (TargetPlace t : targets) {

            float distance = PVector.sub(loc, t.getLoc()).mag();
            if (distance <= sightrange) {
                if (target == null) {
                    target = t.getLoc();
                    currentDistance = distance;
                } else if (distance < currentDistance) {
                    target = t.getLoc();
                    currentDistance = distance;
                }
            }


        }
        return target;

    }
}
